str1 = 'Hello world'

for c in str1:
    print(c)

print("-" * 20)
print(len(str1))
print(str1.count("l"))
print(str1.index("l"))
print(str1[4])

print("-" * 20)
str2 = "hello hello world".replace("hello", "python", 1)
print(str2)

str_list = str2.split(" ")
print(str_list)
print("-" * 20)
str3 = " ".join(str_list)
print(str3)

print("-" * 20)
str4 = "hello\npython\nworld"
print(str4)
print(str4.splitlines())

# 字符串切片
print("-" * 20)
num_str = "0123456789"
print(num_str[2:6]) # 2~5
print(num_str[2:]) #  2~
print(num_str[:6]) # ~5
print(num_str[:]) # 0~9
print(num_str[1::2]) # 13579
print(num_str[2:-1]) # 2~8
print(num_str[-2:]) # 89
print(num_str[::-1]) # 倒序